package icu.qx.pbs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import icu.qx.pbs.domain.PbsProcedure;
import icu.qx.pbs.service.IPbsProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工序Controller
 *
 * @author yong
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/pbs/procedure")
public class PbsProcedureController extends BaseController {
    @Autowired
    private IPbsProcedureService pbsProcedureService;

    /**
     * 查询工序列表
     */
    @RequiresPermissions("pbs:procedure:list")
    @GetMapping("/list")
    public TableDataInfo list(PbsProcedure pbsProcedure) {
        startPage();
        List<PbsProcedure> list = pbsProcedureService.selectPbsProcedureList(pbsProcedure);
        return getDataTable(list);
    }

    /**
     * 查询工序列表
     */
    @RequiresPermissions("pbs:procedure:list")
    @GetMapping("/all")
    public AjaxResult all(PbsProcedure pbsProcedure) {
        List<PbsProcedure> list = pbsProcedureService.selectPbsProcedureList(pbsProcedure);
        return AjaxResult.success(list);
    }

    /**
     * 导出工序列表
     */
    @RequiresPermissions("pbs:procedure:export")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PbsProcedure pbsProcedure) {
        List<PbsProcedure> list = pbsProcedureService.selectPbsProcedureList(pbsProcedure);
        ExcelUtil<PbsProcedure> util = new ExcelUtil<PbsProcedure>(PbsProcedure.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    @RequiresPermissions("pbs:procedure:query")
    @GetMapping(value = "/{procedureCode}")
    public AjaxResult getInfo(@PathVariable("procedureCode") String procedureCode) {
        return success(pbsProcedureService.selectPbsProcedureByProcedureCode(procedureCode));
    }

    /**
     * 新增工序
     */
    @RequiresPermissions("pbs:procedure:add")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PbsProcedure pbsProcedure) {
        return toAjax(pbsProcedureService.insertPbsProcedure(pbsProcedure));
    }

    /**
     * 修改工序
     */
    @RequiresPermissions("pbs:procedure:edit")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PbsProcedure pbsProcedure) {
        return toAjax(pbsProcedureService.updatePbsProcedure(pbsProcedure));
    }

    /**
     * 删除工序
     */
    @RequiresPermissions("pbs:procedure:remove")
    @Log(title = "工序", businessType = BusinessType.DELETE)
    @DeleteMapping("/{procedureCodes}")
    public AjaxResult remove(@PathVariable String[] procedureCodes) {
        return toAjax(pbsProcedureService.deletePbsProcedureByProcedureCodes(procedureCodes));
    }
}
